In JavaScript, arrow functions (=>), also known as lambda expressions, provide a shorter and more concise way to write function expressions.
Equivalent to:
{}
and return
)
Feature | Regular Function | Arrow Function |
---|---|---|
Syntax | Verbose | Concise |
this Behavior | this refers to the function's context | this is lexically inherited (from surrounding scope) |
Can be used as a constructor? | ✅ Yes (new allowed) | ❌ No (new not allowed) |
arguments Object | ✅ Available | ❌ Not available |
Implicit Return | ❌ No | ✅ Yes (for single expressions) |
this
in Arrow FunctionsArrow functions do not have their own this
; they inherit it from the surrounding scope.
this
in Regular vs Arrow Functions
✅ When using short, concise functions
✅ When lexical this
behavior is desired (e.g., inside callbacks)
❌ Avoid when using methods inside objects or when needing arguments
Would you like more examples on how this
behaves in different contexts? 🚀